package net.xinqushi.design;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@SpringBootApplication
@RestController
public class Application {


    @RequestMapping("/doGet")
    public String hello(){

        return "hello world";
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    void test(){
        List<String> list = new ArrayList<String>();
    }
    static class AppList<T>{

        int size;

        Object[] appElement;

        public AppList(){
            appElement = new Object[16];
        }


        void add(T element){
            if(appElement.length > 16) {}//扩容

            appElement[size++] = element;
        }

        T get(int index){
            return (T)appElement[index];
        }

        <T> T[] toArray(T[] a) {
            if (a.length < size)
                // Make a new array of a's runtime type, but my contents:
                return (T[]) Arrays.copyOf(appElement, size, a.getClass());
            System.arraycopy(appElement, 0, a, 0, size);
            if (a.length > size)
                a[size] = null;
            return a;
        }

        public boolean addAll(Collection<? extends T> c) {
            Object[] a = c.toArray();
            int numNew = a.length;
            System.arraycopy(a, 0, appElement, size, numNew);
            size += numNew;
            return numNew != 0;
        }

    }
}
